package com.d.ui.view.advertswitcher;

import com.d.lib.ui.view.advertswitcher.AdvertSwitcher;
import com.d.ui.view.ResourceTable;
import java.util.List;
import ohos.agp.components.Component;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.ToastDialog;
import ohos.app.Context;

public class AdvertSwitcherTextAdapter extends AdvertSwitcher.Adapter<AdvertSwitcherBean> {

  AdvertSwitcherTextAdapter(Context context, List<AdvertSwitcherBean> dataSet, int resId) {
    super(context, dataSet, resId);
  }

  @Override
  public Component makeView() {
    return LayoutScatter.getInstance(mContext).parse(mResId, null, true);
  }

  @Override
  public void bindView(Component view, AdvertSwitcherBean item, int position) {
    Text tvTag = (Text) view.findComponentById(ResourceTable.Id_tv_no);
    tvTag.setText("" + item.no);
    Text tvContent = (Text) view.findComponentById(ResourceTable.Id_tv_content);
    tvContent.setText(item.content);
    view.setClickedListener(component -> {
      new ToastDialog(mContext).setText("Click at: " + position).setAlignment(LayoutAlignment.CENTER).show();
    });
  }
}
